package ru.hh.school;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

//TODO rename maybe?
public class MessagesManager {
    private static Properties messages;

    static {
        init();
    }

    private static void init() {
        String nameOfMessagesResource = "/messages.properties";
        InputStream messagesInputStream = MessagesManager.class.getResourceAsStream(nameOfMessagesResource);
        messages = new Properties();
        try {
            messages.load(messagesInputStream);
        } catch (IOException e) {
            throw new RuntimeException("messages.properties file is missing!", e);
        }
    }

    public static String message(String key, Object... args) {
        return String.format(messages.getProperty(key), args);
    }

    // For test purposes only. Package local
    static void addMessage(String key, String value) {
        messages.put(key, value);
    }
}